package project3.association;

public final class AssociationRule implements Comparable<AssociationRule> {
	
	private ItemSet premise;
	
	private ItemSet consequence;
	
	private double confidence;

	private double support;
	
	public AssociationRule() {
	}
	
	public AssociationRule(ItemSet premise, ItemSet consequence) {
		this.premise = premise;
		this.consequence = consequence;
	}
	
	@Override
	public int hashCode() {
		return 13 * this.premise.hashCode() * this.consequence.hashCode();
	}
	
	@Override
	public boolean equals(Object other) {
		if (null == other) {
			return false;
		}
		if (this == other) {
			return true;
		}
		if (false == (other instanceof AssociationRule)) {
			return false;
		}
		
		AssociationRule otherRule = (AssociationRule) other;
		
		return this.premise.equals(otherRule.premise)
			&& this.consequence.equals(otherRule.consequence);
	}

	@Override
	public String toString() {
		return "AssociationRule [premise=" + premise + ", consequence="
				+ consequence + ", confidence=" + confidence + "]";
	}

	public ItemSet getPremise() {
		return premise;
	}

	public void setPremise(ItemSet premise) {
		this.premise = premise;
	}

	public ItemSet getConsequence() {
		return consequence;
	}

	public void setConsequence(ItemSet consequence) {
		this.consequence = consequence;
	}

	public double getConfidence() {
		return confidence;
	}

	public void setConfidence(double confidence) {
		this.confidence = confidence;
	}

	public int compareTo(AssociationRule other) {
		return Double.compare(this.getConfidence(), other.getConfidence());
	}

	public void setSupport(double support) {
		this.support = support;
	}
	
	public double getSupport() {
		return support;
	}	
}
